<template>
  <a-card :bordered="false" class="card-area">
    <div :class="advanced ? 'search' : null" style="margin-bottom: 20px">
      <!-- 搜索区域 -->
      <a-form layout="horizontal" :form="form">
        <div :class="advanced ? null : 'fold'">
          <a-row>
            <a-col :md="12" :sm="24">
              <a-form-item label="法人行" :labelCol="{ span: 5 }" :wrapperCol="{ span: 16, offset: 1 }">
                <a-select mode="default" :allowClear="true" style="width: 100%" @change="handleInstChange"
                  v-model="query.instId">
                  <a-select-option v-for="r in instIdData" :key="r.label">{{ r.label }}-{{ r.value }}</a-select-option>
                </a-select>
                <!--                <a-input v-if="!this.user.admin" v-model="query.instId" :value="this.user.instId"
                         readonly="readonly"/>-->
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24" v-show="query.instId != ''">
              <a-form-item label="清算日期" :labelCol="{ span: 5 }" :wrapperCol="{ span: 16, offset: 1 }">
                <a-date-picker placeholder="请选择清算日期" @change="value => handlerChange(value, 'batchDate')"
                  v-model="query.batchDate" />
              </a-form-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col :md="12" :sm="24" v-show="query.instId != ''">
              <a-form-item label="业务类型" :labelCol="{ span: 5 }" :wrapperCol="{ span: 16, offset: 1 }">
                <a-select placeholder="请选择业务类型" :allowClear="true" v-model="query.csmcBizType">
                  <a-select-option value="00">00-一般业务</a-select-option>
                  <a-select-option value="01">01-卡券购买/退款</a-select-option>
                  <a-select-option value="02">02-担保支付</a-select-option>
                  <a-select-option value="03">03-组合支付</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24" v-show="query.instId != ''">
              <a-form-item label="对账结果" :labelCol="{ span: 5 }" :wrapperCol="{ span: 16, offset: 1 }">
                <a-select placeholder="请选择对账结果" :allowClear="true" v-model="query.reconRslt">
                  <a-select-option value="00">初始状态</a-select-option>
                  <a-select-option value="01">对平或已销账</a-select-option>
                  <a-select-option value="02">支付平台无，通道多</a-select-option>
                  <a-select-option value="03">支付平台多，通道无</a-select-option>
                  <a-select-option value="04">关键要素不一致</a-select-option>
                  <a-select-option value="05">重复记账</a-select-option>
                  <a-select-option value="06">销账金额不一致</a-select-option>
                  <a-select-option value="07">渠道多</a-select-option>
                  <a-select-option value="08">对账异常结果</a-select-option>
                  <a-select-option value="09">对账正常单边</a-select-option>
                  <a-select-option value="10">组合支付场景，对账部分成功</a-select-option>
                  <a-select-option value="11">组合支付场景，营销对账部分成功</a-select-option>
                  <a-select-option value="12">组合支付场景，支付对账部分成功</a-select-option>
                  <a-select-option value="20">银联代付核心1、银联有流水，核心2无流水</a-select-option>
                  <a-select-option value="21">银联代付核心1有流水，银联、核心2无流水</a-select-option>
                  <a-select-option value="22">银联代付核心1、核心2有流水，银联无流水</a-select-option>
                  <a-select-option value="23">银联代付核心1、核心2无流水，银联有流水</a-select-option>
                  <a-select-option value="24">银联代付核心1、银联无流水，核心2有流水</a-select-option>
                  <a-select-option value="25">银联代付核心1无流水，银联、核心2有流水</a-select-option>
                  <a-select-option value="26">银联代收，支付平台有；银联、核心无</a-select-option>
                  <a-select-option value="27">银联代收，支付平台、银联有；核心无</a-select-option>
                  <a-select-option value="28">银联代收，支付平台、核心有；银联无</a-select-option>
                  <a-select-option value="30">D0，通道对账结果有；核心无</a-select-option>
                  <a-select-option value="31">D0，通道对账结果无；核心有</a-select-option>
                  <a-select-option value="**">不关心对账结果</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col :md="12" :sm="24" v-show="query.instId != ''">
              <a-form-item label="调账状态" :labelCol="{ span: 5 }" :wrapperCol="{ span: 16, offset: 1 }">
                <a-select placeholder="请选择调账状态" :allowClear="true" v-model="query.adjustStatus">
                  <a-select-option value="00">00-未处理</a-select-option>
                  <a-select-option value="01">01-调账中</a-select-option>
                  <a-select-option value="02">02-调账成功</a-select-option>
                  <a-select-option value="03">03-调账失败</a-select-option>
                  <a-select-option value="04">04-不需要调账</a-select-option>
                  <a-select-option value="05">05-调账超时</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </a-row>

        </div>
        <div v-show="query.instId != ''" style="margin-left: 38%">
          <a-button type="primary" @click="search">查询</a-button>
          <a-button style="margin-left: 8px" @click="reset">重置</a-button>
        </div>
      </a-form>
    </div>
    <div v-show="query.instId != ''">
      <!-- 表格区域 -->
      <a-table ref="table" :columns="columns" :rowKey="record => record.primaryKey" :dataSource="dataSource"
        :pagination="pagination" :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" :scroll="{ x: 2200 }"
        @change="handleTableChange">
        <template slot="email" slot-scope="text, record">
          <a-popover placement="topLeft">
            <template slot="content">
              <div>{{ text }}</div>
            </template>
            <p style="width: 90px;margin-bottom: 0">{{ text }}</p>
          </a-popover>
        </template>
        <template slot="operation" slot-scope="text, record">
          <!--          <a-button type="primary" @click="account(record)">调账</a-button>-->
          <a-icon v-hasPermission="['subjectInfo:edit']" type="setting" theme="twoTone" twoToneColor="#4a9ff5"
            @click="account(record)" title="调账"></a-icon>&nbsp;
          <!--          <a-button type="primary" @click="show(record)">调账状态查询</a-button>-->
          <a-icon v-hasPermission="['subjectInfo:view']" type="eye" theme="twoTone" twoToneColor="#42b983"
            @click="show(record)" title="调账状态查询"></a-icon>
          <a-badge v-hasNoPermission="['virtualAccount:edit']" userStatus="warning" text="无权限"></a-badge>
        </template>

      </a-table>

    </div>
  </a-card>
</template>

<script>
import { mapState } from "vuex"
import StatusDetail from "../../../upmp/manualAcctInfo/StatusDetail";
import moment from "moment";

export default {
  name: 'Channel',
  components: { StatusDetail },
  data: function () {
    return {
      form: this.$form.createForm(this),
      advanced: false,
      beanInfo: {},
      operationType: 'view',
      instIdData: [],
      query: {
        instId: '',
        batchDate: '',
        csmcBizType: '',
        reconRslt: '',
        adjustStatus: ''

      },
      statusDetail: {
        visiable: false,
      },
      loading: false,
      dataSource: [],
      selectedRowKeys: [],
      pagination: {
        pageSizeOptions: ['10', '20', '30', '40', '100'],
        defaultCurrent: 1,
        defaultPageSize: 10,
        showQuickJumper: true,
        showSizeChanger: true,
        showTotal: (total, range) =>
          `显示 ${range[0]} ~ ${range[1]} 条记录，共 ${total} 条记录`,
      },
      columns: [
        {
          title: '关键域',
          dataIndex: 'primaryKey'
        },
        {
          title: '清算日期',
          dataIndex: 'batchDate'
        },
        {
          title: '业务类型',
          dataIndex: 'csmcBizType',
          customRender(text) {
            return text ? ['一般业务', '卡券购买/退款', '担保支付', '组合支付',][+text] : ''
          }
        },
        {
          title: '交易类型',
          dataIndex: 'bizProdType',
          customRender(text) {
            return text ? {
              '01': '银联CUPS受理侧',
              '02': '微信支付',
              '03': '支付宝支付',
              '04': '分期',
              '05': '积分',
              '06': '银联小微二维码',
              '07': '网联受理侧',
              '08': '本行渠道业务',
              '11': '银联助农业务',
              '21': '银联线上支付',
              '22': '银联无卡快捷受理侧支付业务',
              '32': '银联无卡快捷代付业务',
              '33': '银联无卡快捷代收业务',
              '23': '银联全渠道_代付业务',
              '24': '银联全渠道_无跳转业务',
              '25': '银联全渠道_代收业务',
              '26': '深圳银联业务',
              '27': '厦门银联业务',
              '31': '银联二维码',
              '34': '银联网关支付',
              '40': '提现',
              '45': '营销',
              '90': '银联CUPS发卡侧',
              '91': '网联发卡侧',
              '92': '银联无卡快捷发卡侧',
              '41': '商户入账失败挂账',
              '42': '风险资金挂账',
              '43': '商户风险资金入账失败挂账',
              '46': 'D0补入账',
              '47': '虚拟账户业务',
              '48': '人行大小额',
              '49': '超级网银',
              '44': '代理商分润',
              '50': '中金支付',
              '51': 'D1垫资资金回填',
              '52': '连锁商户入账',
              '53': '内部户记账',
              '60': '本行渠道D0业务',
              '61': '银联CUPS受理侧D0业务',
              '62': '微信支付D0业务',
              '63': '支付宝支付D0业务',
              '64': '银联无卡快捷受理侧支付D0业务',
              '65': '银联全渠道_无跳转D0业务',
              '66': '银联网关支付D0业务',
              '67': '银联二维码D0业务',
              '*': '所有业务',
            }[text] : ''
          }
        },
        {
          title: '商户号',
          dataIndex: 'mchntNo'
        },
        {
          title: '交易金额',
          dataIndex: 'transAmt'
        },
        {
          title: '通道费用',
          dataIndex: 'payChannelFee'
        },
        {
          title: '应收交换费',
          dataIndex: 'cretFee'
        },
        {
          title: '应付交换费',
          dataIndex: 'debtFee'
        },
        {
          title: '转接清算费',
          dataIndex: 'swtServiceFee'
        },
        {
          title: '对账结果',
          dataIndex: 'reconRslt',
          customRender(text) {
            return text ? {
              '00': '初始状态',
              '01': '对平或已销账',
              '02': '支付平台无，通道多',
              '03': '支付平台多，通道无',
              '04': '关键要素不一致',
              '05': '重复记账',
              '06': '销账金额不一致 ',
              '07': '渠道多',
              '08': '对账异常结果',
              '09': '对账正常单边',
              '10': '组合支付场景，积分对账部分成功',
              '11': '组合支付场景，营销对账部分成功',
              '12': '组合支付场景，支付对账部分成功',
              '20': '银联代付核心1、银联有流水，核心2无流水',
              '21': '银联代付核心1有流水，银联、核心2无流水',
              '22': '银联代付核心1、核心2有流水，银联无流水',
              '23': '银联代付核心1、核心2无流水，银联有流水',
              '24': '银联代付核心1、银联无流水，核心2有流水',
              '25': '银联代付核心1无流水，银联、核心2有流水',
              '26': '银联代收，支付平台有；银联、核心无',
              '27': '银联代收，支付平台、银联有；核心无',
              '28': '银联代收，支付平台、核心有；银联无',
              '30': 'D0，通道对账结果有；核心无',
              '31': 'D0，通道对账结果无；核心有',
              '**': '不关心对账结果',
            }[text] : ''
          }
        },
        {
          title: '调账状态',
          dataIndex: 'adjustStatus',
          customRender(text) {
            return text ? ['未调账', '调账中', '调账成功', '调账失败', '不需要调账', '调账超时'][+text] : ''
          }
        },
        {
          title: '终端号',
          dataIndex: 'termNo'
        },
        {
          title: '订单号',
          dataIndex: 'orderId'
        },
        {
          title: '交易传输时间',
          dataIndex: 'transTime'
        },
        {
          title: '收单机构号',
          dataIndex: 'acqInstCode'
        },
        {
          title: '法人行',
          dataIndex: 'instId'
        },
        {
          title: '审核状态',
          dataIndex: 'auditStatus',
          customRender(text) {
            return text ? {
              '00': '待提交审批',
              '01': '新增-审批流程中',
              '02': '新增-审批通过',
              '03': '新增-审批拒绝',
              '11': '注销-审批流程中',
              '12': '注销-审批通过',
              '13': '注销-审批拒绝',
              '21': '停用-审批流程中',
              '22': '停用-审批通过',
              '23': '停用-审批拒绝',
              '31': '启用-审批流程中',
              '32': '启用-审批通过',
              '33': '启用-审批拒绝',
              '40': '修改-待提交审批',
              '41': '修改-审批流程中',
              '42': '修改-审批通过',
              '43': '修改-审批拒绝',
            }[text] : ''
          }
        },
        { title: '交易码', dataIndex: 'txnNum' },
        {
          title: '操作',
          scopedSlots: { customRender: 'operation' }
        },
      ],

    }
  },
  computed: {
    ...mapState({
      user: state => state.account.user,
    })
  },

  mounted() {
    this.$get('admin/upmporg/getInstList').then((r) => {
      this.instIdData = r.data
    })
    // this.search();
  },

  methods: {
    show(record) {
      if (record.adjustStatus == "00") {
        this.$message.warning("调账状态不需要调账不支持调账状态查询");
        return
      }
      if (record.adjustStatus == "01") {
        this.$message.warning("调账状态未调帐不支持调账状态查询");
        return
      }
      if (record.adjustStatus == "02") {
        this.$message.warning("调账状态调账成功不支持调账状态查询");
        return
      }
      if (record.adjustStatus == "04") {
        this.$message.warning("调账状态不需要调账不支持调账状态查询");
        return
      }
      let params = {}
      params.id = record.primaryKey
      params.instId = record.instId
      params.oprType = '01'
      this.$get('/admin/upmp/bManualAcctInfo/statusdetailPage', params).then((r) => {
        console.log("statusdetailPage==", r)
        this.$refs.statusDetail.setStatusDetailFormValues(r)
        this.statusDetail.visiable = true

      })

    },

    handleTableChange(pagination) {
      // 将这三个参数赋值给Vue data，用于后续使用
      this.paginationInfo = pagination
      this.fetch({
        ...this.query,
      })
    },

    handlerChange(value, item) {
      if (value != null) {
        value = moment(value).format('YYYYMMDD');
      }
      this.query.batchDate = value
    },

    search(e) {
      // console.log(this.query.batchDate+"***   *** date")
      let params = {}
      params.instId = this.query.instId
      params.batchDate = this.query.batchDate
      params.csmcBizType = this.query.csmcBizType
      params.reconRslt = this.query.reconRslt
      params.adjustStatus = this.query.adjustStatus
      this.fetch({
        ...params,
      })

    },
    reset() {
      this.query.instId = ''
      this.query.batchDate = ''
      this.query.csmcBizType = ''
      this.query.reconRslt = ''
      this.query.adjustStatus = ''
      // 取消选中
      this.selectedRowKeys = []
      // 重置分页
      this.$refs.table.pagination.current = this.pagination.defaultCurrent
      if (this.paginationInfo) {
        this.paginationInfo.current = this.pagination.defaultCurrent
        this.paginationInfo.pageSize = this.pagination.defaultPageSize
      }
      // 重置查询参数
      // this.query = {}
      // // 清空时间选择
      // this.$refs.createTime.reset()
      this.fetch()
    },

    account(record) {
      if (record.adjustStatus != "00") {
        this.$message.warning("调账状态非未处理不能进行调账");
        return
      }
      let params = {}
      this.$get('/admin/csmc/ReconerrTxn/saveData', record).then((r) => {
        console.log("saveData==", r)
        this.$refs.statusDetail.setStatusDetailFormValues(r)
        this.statusDetail.visiable = true

      })
    },

    onSelectChange(selectedRowKeys) {   //接收数组，存放到前面定义的数组中
      this.selectedRowKeys = selectedRowKeys
    },

    handleInstChange(value) {
      this.query.instId = value;
      if (value != "") {
        this.paginationInfo = {}
        let params = {}
        params.instId = value;
        // params.userId = this.user.id;
        this.$get('/admin/csmc/Channels/findPage', { ...params }).then((r) => {
          this.dataSource = r.data.rows;
          this.search();
        })
      }
    },

    fetch(params = {}) {
      params.userId = this.user.id;
      this.loading = true
      if (this.paginationInfo) {
        // 如果分页信息不为空，则设置表格当前第几页，每页条数，并设置查询分页参数
        this.$refs.table.pagination.current = this.paginationInfo.current ? this.paginationInfo.current : this.pagination.defaultCurrent
        this.$refs.table.pagination.pageSize = this.paginationInfo.pageSize ? this.paginationInfo.pageSize : this.pagination.defaultPageSize
        params.pageSize = this.paginationInfo.pageSize ? this.paginationInfo.pageSize : this.pagination.defaultPageSize
        params.pageNum = this.paginationInfo.current ? this.paginationInfo.current : this.pagination.defaultCurrent
      } else {
        // 如果分页信息为空，则设置为默认值
        params.pageSize = this.pagination.defaultPageSize
        params.pageNum = this.pagination.defaultCurrent
      }
      this.$get('/admin/csmc/Channels/findPage', {
        ...params
      }).then((r) => {
        let data = r.data
        const pagination = { ...this.pagination }
        pagination.total = data.total
        this.dataSource = data.rows
        this.pagination = pagination
        this.loading = false
      })
    },


  }

}
</script>

<style lang="less" scoped>
@import "../../../../../../static/less/Common";
</style>
